/**
 * Created by fengling on 2016/5/10.
 */
var userid=getParameter('userid');
var token=getParameter('token');
$(function() {

    function getQS(divContainer){
        $.ajax({
            url:httpurl+"/mobile/staff/webtalk/queryQSTJ",
            type:"POST",
            dataType:"jsonp",
            jsonp: "callback",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback)
            data:{qs:'',token:token},
            success:function(result){
                if(result['code']=='10001'){
                    var data=result.infosDetails;
                    var html = [];
                    for(var i=0;i<data.length;i++){
                        html.push('<option value="'+data[i].ID+'">第 '+data[i].QS+' 期</option>');
                    }
                    divContainer.html(html.join(''));
                }
            }
        });
    }

    function dkxq(table,gszlid,dpzs){
        $.ajax({
            url:httpurl+"/mobile/staff/webtalk/queryGszldkxq",
            type:"POST",
            dataType:"jsonp",
            jsonp: "callback",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback)
            data:{gszlid:gszlid,dpzs:dpzs,token:token},
            success:function(result){
                if(result['code']=='10001'){
                    var data=result.infosDetails;
                    var html = [];
                    for(var i=0;i<data.length;i++){
                        html.push('<div><b><u><span class="content">'+data[i]['ZXR']+'：</span></u></b>' +
                        '<span class="content">'+data[i]['GD']+'</span>' +
                        '</div>');
                    }
                    table.html(html.join(''));
                }
            }
        });
    }

    function getGDTJ(divID,gszlid){
        $.ajax({
            type: "post",
            url: httpurl+"/mobile/staff/webtalk/getGDTJ",
            data:{token:token,gszlid:gszlid},
            dataType: "jsonp",
            jsonp: "callback",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback)
            success: function(result){
                if(result['code']=='10001'){
                    var infoDetails = result.infosDetails;
                    var KZ = parseInt(nvl(infoDetails[0].KZ,0));
                    var KP = parseInt(nvl(infoDetails[0].KP,0));
                    var KD = parseInt(nvl(infoDetails[0].KD,0));
                    var sum = KZ+KP+KD;
                    if(sum==0){sum=1;}
                    var KZBL = KZ/sum;
                    var KPBL = KP/sum;
                    var KDBL = KD/sum;
                    var data = [];
                    data.push(['看涨',KZBL]);
                    data.push(['看平',KPBL]);
                    data.push(['看跌',KDBL]);
                    createPieChart(divID,'申万宏源股市周论多空分布',data,'申万宏源股市周论多空分布')
                }
            },
            error: function(){
                showmessage('取图形失败!');
            }
        });
    }

    function createPieChart (renderDiv, name, data, titleText) {
        renderDiv.highcharts({
            chart: {
                plotBackgroundColor: null,
                plotBorderWidth: null,
                plotShadow: false
            },
            title: {
                text: titleText
            },
            credits: {
                enabled: false//关闭图表版权
            },
            tooltip: {
                pointFormat: '{series.name}: <b>{point.percentage:.2f}%</b>'
            },
            plotOptions: {
                pie: {
                    allowPointSelect: true,
                    cursor: 'pointer',
                    dataLabels: {
                        enabled: true,
                        format: '{point.percentage:.2f}%'
                    },
                    showInLegend: true
                }

            },
            series: [
                {
                    type: 'pie',
                    name: name,
                    data: data
                }
            ]
        });

    }


    var container = $('#dkxq');
    getQS($('#qs',container));
    $('#qs',container).change(function(){
        getGDTJ($('#gszlbttj',container),$(this).val());
        dkxq($('#kdgd',container),$(this).val(),'1');  //看涨
        dkxq($('#kpgd',container),$(this).val(),'2');  //看平
        dkxq($('#kkgd',container),$(this).val(),'3');  //看空
    }).change();
})